using System;
using System.Xml;

using ECCIT.Configuration;

namespace ECCIT.Web.Configuration
{
	/// <summary>
	/// </summary>
	[Serializable]
	public class WebControlCssManager : ConfigManager
	{
		private string _controlNamespace;
		private string _controlName;
		private string _propertyName;
		private string _cssClass;

		public string CssClass
		{
			get{ return _cssClass; }
		}

		/// <summary>
		///		The constructor without any parameter is only designed for AjaxPro reflection
		/// </summary>
		public WebControlCssManager(){}

		public WebControlCssManager(string appVirtualPath, string controlNamespace, string controlName, string propertyName) : base(appVirtualPath, "WebControlCssClass.config")
		{
			_controlNamespace = controlNamespace;
			_controlName = controlName;
			_propertyName = propertyName;

			XmlDocument configDoc = GetConfigDocument();
			
			_cssClass = GetCssClass(configDoc, controlNamespace, controlName, propertyName);
		}

		private string GetCssClass(XmlDocument configDoc, string controlNamespace, string controlName, string propertyName)
		{
			string css = string.Empty;
			XmlNode controlNode = configDoc.DocumentElement.SelectSingleNode("./WebControl[@Namespace='" + controlNamespace + "' and @Name='" + controlName + "']");
			if(controlNode != null)
			{
				css = controlNode.SelectSingleNode("./Property[@Name='" + propertyName + "']").Attributes["CssClass"].Value;
			}
			
			return css;
		}
	}
}
